<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态更改属性</title>
    <script type="text/javascript" src="https://vuejs.org/js/vue.js"></script>
    <style>
        .fade-enter-active, .fade-leave-active{
            transition: opacity 2s;
        }
        .fade-enter, .fade-leave-active{
            opacity:0;
        }
        p{
            margin: 0;
            position: absolute;
            font-size:3em;
        }
    </style>
</head>
<body>
<div id="app">
    <button @click="kisses++">💋Kiss!</button>
    <transition name="fade">
        <p :key="transformation">{{emoji}}{{transformation}}</p>
    </transition>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            kisses: 0
        },
        computed: {
            transformation(){
                if (this.kisses < 3) {
                    return 'frog';
                }
                if (this.kisses >= 3 && this.kisses <= 5) {
                    return 'princess';
                }
                if (this.kisses > 5) {
                    return 'santa';
                }
            },
            emoji(){
                switch (this.transformation) {
                    case 'frog':
                        return '🐸';
                    case 'princess':
                        return '👸';
                    case 'santa':
                        return '🎅🏻';
                }
            }
        }
    })
</script>
</body>
</html>